<?php

//error_reporting(E_ALL);
//ini_set('display_errors', 0);

require_once 'init_fu.php';
require_once $FU->dir->lib.'RL/UseScript.php';

$rh = new RL_UseScript();

	$rh->useClass("RL_Debug");
	$debug = new RL_Debug(/*min error level for halt*/3);
	
	$config_dir = $FU->dir->config;
	require_once "$config_dir/conf.d/db.php";
	
	$rh->useClass("RL_DBAL");
	$db = new RL_DBAL($debug);
	$db->loadConfig($config);
	
	// соединение с БД
	$db->connect();

	include_once 'includes/type.php';
	
	$td = TypeDomain::instance();
	$td->addLoader(new KarniTypeLoader("$config_dir/type.d"));
	$td->addLoader(new DocTypeLoader("$config_dir/conf.d/doctype.php"));

	// add default types
	$td->setType('atom'        , new TAtom());
	$td->setType('object'      , new TObject());
	$td->setType('collection'  , new TCollection(array()));
	$td->cloneType('string'    , 'atom');
	$td->cloneType('integer'   , 'atom');
	$td->cloneType('bool'      , 'atom');
	$td->aliasType('boolean'   , 'bool');
	$td->cloneType('text'      , 'atom');
	$td->cloneType('datetime'  , 'atom');
	$td->cloneType('timestamp' , 'atom');

	require_once "$config_dir/conf.d/store.php";
	require_once $config['code'].'/stores/'.$config['dbms'].'store.php';
	$store_type = $config['dbms'].'store';

	$store = new $store_type($config, $db, $td);

	require_once('lib/rss_publish.php');
	
	return 0;
